package servlet;

import bean.load;
import bean.record;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(name = "Register1", value = "/Register1")
public class Register1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        load ld = new load();
        String SQL="select*from rec";
        ArrayList<record> ar = new ArrayList<record>();
        ar=ld.loadrecord(SQL);
        int id1=(ar.size()+1);
        HttpSession session = request.getSession();
        String ur=(String) session.getAttribute("ur");//用户名
        String ur1=request.getParameter("ur1");//医生编号
        String rec_time="2023/1/7";
        String SQL1,SQL2;
        //有删减
        load ld1=new load();
        SQL1="insert into reg(reg_id,id,doc_id,reg_time) value('"+id1+"','"+ur+"','"+ur1+"','"+rec_time+"')";
        ld1.opert(SQL1);
        //记录，无删减
        load ld2=new load();
        SQL2="insert into rec(reg_id,id,doc_id,reg_time) value('"+id1+"','"+ur+"','"+ur1+"','"+rec_time+"')";
        ld2.opert(SQL2);
        response.sendRedirect("/HospitalAppointmentReg_Sys_war_exploded/jsp/table2.jsp");//页面跳转
    }
}
